<template>
  <div>
    <td>名称</td>
    <td><input type="text" v-model="data.sname" /></td>
    <td>创建人</td>
    <td><input type="text" v-model="data.create" /></td>
    <td><input type="button" value="查询" @click="list" /></td>
    <h1>房号列表</h1>
    <table class="table table-borsered">
      <tbody>
        <tr>
          <td>id</td>
          <td>房号</td>
          <td>名称</td>
          <td>状态</td>
          <td>创建人</td>
          <td>操作</td>
        </tr>
        <tr v-for="a in info.list">
          <td>{{ a.sid }}</td>
          <td>{{ a.scode }}</td>
          <td>{{ a.sname }}</td>
          <td>{{ a.stype == 1 ? "启用" : "禁用" }}</td>
          <td>{{ a.create }}</td>
          <td>
            <input
              type="button"
              value="禁用"
              @click="update(a.sid)"
              v-if="a.stype == 1"
            />
            <input
              type="button"
              value="启用"
              @click="update(a.sid)"
              v-if="a.stype != 1"
            />
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { reactive, onMounted } from "vue";
let info: any = reactive({
  list: [],
});
let data: any = reactive({
  sname: "",
  create: "",
});
onMounted(() => {
  list();
});
const update = (sid: any) => {
  axios({
    url: "/api/Sto/Update",
    method: "get",
    params: {
      sid: sid,
    },
  }).then((res) => {
    console.log(res);
    if (res.data > 0) {
      alert("修改成功");
      list();
      return;
    } else {
      alert("修改失败");
      return;
    }
  });
};
const list = () => {
  axios({
    url: "/api/Sto/GetSto",
    method: "get",
    params: data,
  }).then((res) => {
    console.log(res);
    info.list = res.data;
  });
};
</script>

<style scoped></style>
